<script setup lang="ts">
import type {TabsPaneContext} from "element-plus";
import {Search} from "@element-plus/icons-vue";
import {useIndexStore} from "@/store/main";
import {ref} from "vue";
import PcDialogAddUser from "@/components/pc//main/pc-dialog-addUser.vue";
import PcDialogAddGroup from "@/components/pc/main/pc-dialog-addGroup.vue";
import {useUserStore} from "@/store/user";

const userStore = useUserStore()

const dialogVisible = ref(false)
const handleClose = () => {
  dialogVisible.value = false
}


const activeName = ref('first')
const handleClick = (tab: TabsPaneContext, event: Event) => {
  console.log(tab, event)
}
</script>

<template>
  <div @click="dialogVisible = true">
    添加好友/群聊
  </div>
  <el-dialog
      v-model="dialogVisible"
      width="700"
      :before-close="handleClose"
      :append-to-body="true"
  >
    <template #header>
      <div class="text-center">
        添加好友或群聊
      </div>
    </template>
    <div>
      <div class="p-1">
        <el-input
            v-model="userStore.search_key"
            placeholder="输入关键词"
            :prefix-icon="Search"
            @input="userStore.on_search('global')"
        />
      </div>
      <el-tabs v-model="activeName" class="demo-tabs p-1" @tab-click="handleClick">
        <el-tab-pane label="全部" name="first">
          <div v-if="userStore.search_users.length > 0">
            <div class="p-2 text-xl">用户</div>
            <div class="w-full flex flex-wrap">
              <div class="w-[50%] flex justify-between *:m-3" v-for="user in userStore.search_users.slice(0,4)">
                <div class="w-[20%]">
                  <el-avatar :size="50" :src="user.avatar"/>
                </div>
                <div class="w-[50%] flex *:w-full flex-wrap ml-2 text-[12px] items-center">
                  <div>{{ user.name }}</div>
                  <div>{{ user.account }}</div>
                </div>
                <div class="w-[30%] flex justify-center items-center">
                  <pc-dialog-add-user :add_user="user" type="linkman"/>
                </div>
              </div>
            </div>
          </div>
          <div v-if="userStore.search_users.length > 0">
            <div class="p-2 text-xl">群聊</div>
            <div class="w-full flex flex-wrap">
              <div class="w-[50%] flex justify-between *:m-3" v-for="group in userStore.search_groups.slice(0,4)">
                <div class="w-[20%]">
                  <el-avatar :size="50" :src="group.avatar"/>
                </div>
                <div class="w-[50%] flex *:w-full flex-wrap ml-2 text-[12px] items-center">
                  <div>{{ group.title }}</div>
                  <div>{{ group.account }}</div>
                </div>
                <div class="w-[30%] flex justify-center items-center">
                  <pc-dialog-add-user :add_user="group" type="group"/>
                </div>
              </div>
            </div>
          </div>
          <el-empty v-else description="输入关键词搜索"/>
        </el-tab-pane>
        <el-tab-pane label="好友" name="second">
          <div v-if="userStore.search_users.length > 0">
            <div class="w-full flex flex-wrap">
              <div class="w-[50%] flex justify-between *:m-3" v-for="user in userStore.search_users">
                <div class="w-[20%]">
                  <el-avatar :size="50" :src="user.avatar"/>
                </div>
                <div class="w-[50%] flex *:w-full flex-wrap ml-2 text-[12px] items-center">
                  <div>{{ user.name }}</div>
                  <div>{{ user.account }}</div>
                </div>
                <div class="w-[30%] flex justify-center items-center">
                  <pc-dialog-add-user :add_user="user" type="linkman"/>
                </div>
              </div>
            </div>
          </div>
          <el-empty v-else description="输入关键词搜索"/>
        </el-tab-pane>
        <el-tab-pane label="群聊" name="third">
          <div v-if="userStore.search_users">
            <div class="w-full flex flex-wrap">
              <div class="w-[50%] flex justify-between *:m-3" v-for="group in userStore.search_groups">
                <div class="w-[20%]">
                  <el-avatar :size="50" :src="group.avatar"/>
                </div>
                <div class="w-[50%] flex *:w-full flex-wrap ml-2 text-[12px] items-center">
                  <div>{{ group.name }}</div>
                  <div>{{ group.account }}</div>
                </div>
                <div class="w-[30%] flex justify-center items-center">
                  <pc-dialog-add-user :add_user="group" type="group"/>
                </div>
              </div>
            </div>
          </div>
          <el-empty v-else description="输入关键词搜索"/>
        </el-tab-pane>
      </el-tabs>
    </div>
  </el-dialog>
</template>

<style scoped>

</style>